import 'dart:convert';

import 'package:ecy_app_flutter/ecycommon/EcyRequestBaseManager.dart';
import 'package:ecy_app_flutter/ecycommon/utils/EcyRandomUtil.dart';
import 'package:ecy_app_flutter/model/EcyApiCommonPage.dart';
import 'package:ecy_app_flutter/routes/blind_box/exchange_market/models/exchange_user_group.dart';
import 'package:ecy_app_flutter/routes/blind_box/model/EcyISwap.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ecy_app_flutter/routes/blind_box/exchange_market/models/exchange_card.dart';
import 'package:ecy_app_flutter/routes/blind_box/exchange_market/service/exchange_service.dart';
import 'package:ecy_app_flutter/routes/blind_box/exchange_market/pages/EcyExchangeSelectTargetPage.dart';
import 'package:ecy_app_flutter/ecycommon/EcyAPI.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import '../../ecycommon/utils/EcyLogger.dart';
import '../../model/EcyApiCommonResponse.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../model/SysDictData.dart';
import 'model/EcyIllustrate.dart';

class BlindBoxMyAssets extends StatefulWidget {
  // final ExchangeCard card;   
  
  BlindBoxMyAssets({
    super.key,
    ExchangeCard? card,
    List<ExchangeUserGroup>? userGroups,
  });
  
  get card => null;

  @override
  _BlindBoxMyAssetsState createState() => _BlindBoxMyAssetsState();
}
  
class _BlindBoxMyAssetsState extends State<BlindBoxMyAssets> with SingleTickerProviderStateMixin  {
  final ExchangeService _exchangeService = ExchangeService();
  late TabController _tabController;

  int _total = 0;
  int _currentPage = 1;
  bool _hasMore = false;
  final List<EcyISwap> ISwapList = [];
  bool _isSelected = false;
  bool _selectMode = false; // 是否进入选择模式
  bool _selectAll = false; // 全选状态
  Set<int> _selectedCardIds = {}; // 选中的卡片id集合
  List<ExchangeUserGroup> userGroups = 
  [ExchangeUserGroup(userName: "userName1", userAvatar: EcyRandomUtil.randomIconUrl(), 
  offerCards: [ExchangeCard(id: 0, name: "1", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: true)], 
  wantCards: [ExchangeCard(id: 1, name: "2", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: false),ExchangeCard(id: 2, name: "123", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: false)],
   canExchange: null),
   ExchangeUserGroup(userName: "userName2", userAvatar: EcyRandomUtil.randomIconUrl(), 
  offerCards: [ExchangeCard(id: 2, name: "3", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: true)], 
  wantCards: [ExchangeCard(id: 3, name: "4", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: false),ExchangeCard(id: 2, name: "123", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: false)],
   canExchange: true)];
  ExchangeCard card = ExchangeCard(id: 4, name: "5", imageUrl: EcyRandomUtil.randomIconUrl(), expiryTime: null, owned: true);
  final RefreshController _refreshController = RefreshController(initialRefresh: false);
  // 用于记录每个分组的展开状态
  Map<int, bool> _expansionStatus = {};

  int get _selectedCount => _selectedCardIds.length;
  int get _totalPrice => _selectedCount * 15;
  int get _remainForFreeShipping => (999 - _totalPrice) > 0 ? (999 - _totalPrice) : 0;
  /// 运费
  int? postage = 0;
  /// 发货说明
  String illustrateHtml = "";

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
    getBaseData();
    requestData();
    // _loadUserGroups();
  }

  // Future<void> _loadUserGroups() async {
  //   final groups = await _exchangeService.getUserGroups(widget.card?.id ?? 0);
  //   setState(() {
  //     userGroups = groups;
  //   });
  // }
  Future<void>requestData({int page = 1}) async{
      try{
         Map<String, dynamic> body = {
          "pageIndex":page,
           "pageSize":10,
         };
      var response =  await EcyRequestbasemanager().get(EcyAPI.myPublish.url,body);
      if(response != null){
         var commonResponse =   EcyApiCommonResponse.fromJson(response, (response) => json);
         if(commonResponse.code == 0 || commonResponse.code == 200){
            EcyApiCommonPage<EcyISwap> commonPage = EcyApiCommonPage.fromJson(response["data"],(json) => EcyISwap.fromJson(json));
            _total = commonPage.pages ?? 0;
            _currentPage = commonPage.current ?? 0;
            var myISwapList = commonPage.records ?? [];
            if(page == 1){
              ISwapList.clear();
            }
            setState(() {
              ISwapList.addAll(myISwapList);
              _hasMore = _total > _currentPage;
            });
         }
      }
      }catch(e){
        EcyLogger.log("获取失败$e");
      }
  }

  /// 查询包邮政策和发货说明
  Future<void> getBaseData() async {
    Map<String, dynamic> body = {};
    List<dynamic> response = await Future.wait([
      EcyRequestbasemanager().get(EcyAPI.freight.url, body),
      EcyRequestbasemanager().get("${EcyAPI.illustrate.url}0", body)
    ]);
    EcyApiCommonResponse freightRes = EcyApiCommonResponse.fromJson(response[0], (json) => json);
    EcyApiCommonResponse illustrateRes = EcyApiCommonResponse.fromJson(response[1], (json) => json);
    if (freightRes.code != 0 && freightRes.code != 200) {
      EasyLoading.showToast(freightRes.msg ?? "请稍后再试", duration: const Duration(seconds: 1));
      return;
    }
    if (illustrateRes.code != 0 && illustrateRes.code != 200) {
      EasyLoading.showToast(freightRes.msg ?? "请稍后再试", duration: const Duration(seconds: 1));
      return;
    }
    if (freightRes.data is List && freightRes.data.isNotEmpty) {
      final item = freightRes.data[0];
      if (item is Map<String, dynamic>) {
        SysDictData sysDictData = SysDictData.fromJson(item);
        final dictValue = sysDictData.dictValue;
        if (dictValue is String && dictValue.isNotEmpty) {
          postage = int.tryParse(dictValue) ?? postage; // 保留原值或设置默认值
        }
      }
    }
    EcyIllustrate illustrate = EcyIllustrate.fromJson(illustrateRes.data);
    final content = illustrate.content;
    if (content is String && content.isNotEmpty) {
      illustrateHtml = content;
    }
  }

  //下拉刷新
  Future<void> _onRefresh() async {
    _currentPage = 1;
    await requestData(page: _currentPage);
    _refreshController.refreshCompleted();
    // 重置上拉加载状态
    if (_hasMore) {
      _refreshController.loadComplete();
    } else {
      _refreshController.loadNoData();
    }
  }

  //上拉加载更多
  Future<void> _onLoading() async {
    if (_hasMore) {
      _currentPage++;
      await requestData(page: _currentPage);
      _refreshController.loadComplete();
    } else {
      _refreshController.loadNoData();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
          backgroundColor: const Color(0xFFF5F5F5),
          appBar: AppBar(
                    centerTitle: true,
                    backgroundColor: Colors.white,
                    elevation: 0,
                    leading: IconButton(
                      icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
                      onPressed: () => Navigator.of(context).pop(),
                    ),
                    title: const Text(
                      '我的痛柜',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 18,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                body: Container(
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
                        decoration: BoxDecoration(color: Colors.transparent),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            _selectMode
                              ? Row(
                                  children: [
                                    Checkbox(
                                      value: _selectAll,
                                      onChanged: (val) {
                                        setState(() {
                                          _selectAll = val!;
                                          _selectedCardIds.clear();
                                          if (_selectAll) {
                                            for (var group in userGroups) {
                                              for (var card in group.offerCards) {
                                                _selectedCardIds.add(card.id);
                                              }
                                            }
                                          }
                                        });
                                      },
                                    ),
                                    Text('全选', style: TextStyle(fontSize: 12, color: Color(0xFFF55F4E))),
                                  ],
                                )
                              : Text("发货订单满${postage}元包邮", style: TextStyle(fontSize: 12, color: Color(0xFFF55F4E))),
                            Row(
                              children: [
                                GestureDetector(
                                  onTap: () {
                                    // 处理点击事件
                                    showDialog(context: context, builder: (context) => _showDialog());
                                  },
                                  child: const Text(
                                    '发货说明'
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () {
                                    showDialog(context: context, builder: (context) => _showDialog());
                                  },
                                  child: Icon(Icons.arrow_forward_ios, color: Color(0xFFF62EBD)),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                      Expanded(
                        child: ListView(
                          children: [
                            ...userGroups.asMap().entries.map((entry) {
                              int idx = entry.key;
                              var group = entry.value;
                              bool isExpanded = _expansionStatus[idx] ?? false;
                              return Container(
                                margin: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(16),
                                  boxShadow: const [
                                    BoxShadow(
                                      color: Colors.black12,
                                      blurRadius: 6,
                                      offset: Offset(0, 2),
                                    ),
                                  ],
                                ),
                                child: Theme(
                                  data: Theme.of(context).copyWith(
                                    dividerColor: Colors.transparent,
                                    splashColor: Colors.transparent,
                                    highlightColor: Colors.transparent,
                                  ),
                                  child: ExpansionTile(
                                    tilePadding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                                    title: Row(
                                      children: [
                                        CircleAvatar(
                                          backgroundImage: NetworkImage(group.userAvatar ?? ''),
                                          radius: 18,
                                        ),
                                        SizedBox(width: 12),
                                        Text(
                                          group.userName,
                                          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
                                        ),
                                      ],
                                    ),
                                    trailing: AnimatedRotation(
                                      turns: isExpanded ? 0.5 : 0.0, // 0.5圈=180°
                                      duration: Duration(milliseconds: 200),
                                      child: Icon(Icons.keyboard_arrow_down_rounded, color: Colors.pinkAccent, size: 28),
                                    ),
                                    onExpansionChanged: (expanded) {
                                      setState(() {
                                        _expansionStatus[idx] = expanded;
                                      });
                                    },
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
                                        child: Wrap(
                                          spacing: 12,
                                          runSpacing: 12,
                                          children: group.offerCards.map((card) => _buildCustomCard(
                                            card,
                                            selectMode: _selectMode,
                                            selected: _selectedCardIds.contains(card.id),
                                            onChanged: (val) {
                                              setState(() {
                                                if (val == true) {
                                                  _selectedCardIds.add(card.id);
                                                } else {
                                                  _selectedCardIds.remove(card.id);
                                                }
                                                // 自动同步全选状态
                                                _selectAll = _selectedCardIds.length == userGroups.expand((g) => g.offerCards).length;
                                              });
                                            },
                                          )).toList(),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              );
                            }),
                          ],
                        ),                   
                      )
                    ]
                  ),
                ),

        bottomNavigationBar: _buildSettlementBar(),
      );
  }

  Widget _buildSettlementBar() {
    return Container(
      height: 150.h,
      color: Colors.white,
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
      child: Column(
        children: [
          _selectMode
            ? Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('已选中$_selectedCount件'),
                  SizedBox(width: 8),
                  Text(
                    _remainForFreeShipping > 0
                        ? '还差$_remainForFreeShipping元就可以包邮啦~'
                        : '已满足包邮条件~',
                    style: TextStyle(color: Colors.pink, fontSize: 12),
                  ),
                ],
              )
            : SizedBox(),
          const SizedBox(height: 10),
          if (!_selectMode) 
            const SizedBox(height: 25),
          if (!_selectMode)
            Container(
              width: MediaQuery.of(context).size.width * 0.8,
              height: 40.h,
              decoration: BoxDecoration(
                gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
                borderRadius: BorderRadius.circular(24),
              ),
              child: TextButton(
                onPressed: () {
                  setState(() {
                    _selectMode = true;
                    _selectAll = false;
                    _selectedCardIds.clear();
                  });
                },
                style: TextButton.styleFrom(
                  padding: EdgeInsets.zero,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                ),
                child: Text(
                  '发货',
                  style: TextStyle(
                    fontFamily: "PingFang SC",
                    fontWeight: FontWeight.w700,
                    fontSize: 16.sp,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
          if (_selectMode) ...[
            Container(
              width: MediaQuery.of(context).size.width * 0.8,
              height: 40.h,
              decoration: BoxDecoration(
                gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
                borderRadius: BorderRadius.circular(24),
              ),
              child: TextButton(
                onPressed: _selectedCount == 0 ? null : () async {
                  if (_remainForFreeShipping > 0) {
                    final result = await _showConfirmDialog();
                    if (result != true) return;
                  }
                  // 这里写你的发货逻辑
                },
                style: TextButton.styleFrom(
                  padding: EdgeInsets.zero,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                  backgroundColor: _selectedCount == 0 ? Colors.grey[300] : null,
                ),
                child: Text(
                  '确定',
                  style: TextStyle(
                    fontFamily: "PingFang SC",
                    fontWeight: FontWeight.w700,
                    fontSize: 16.sp,
                    color: _selectedCount == 0 ? Colors.grey : Colors.white,
                  ),
                ),
              ),
            ),
            const SizedBox(height: 10),
            Container(
              width: MediaQuery.of(context).size.width * 0.8,
              height: 40.h,
              decoration: BoxDecoration(
                gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
                borderRadius: BorderRadius.circular(24),
              ),
              child: TextButton(
                onPressed: () {
                  setState(() {
                    _selectMode = false;
                    _selectAll = false;
                    _selectedCardIds.clear();
                  });
                },
                style: TextButton.styleFrom(
                  padding: EdgeInsets.zero,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                ),
                child: Text(
                  '取消',
                  style: TextStyle(
                    fontFamily: "PingFang SC",
                    fontWeight: FontWeight.w700,
                    fontSize: 16.sp,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
          ],
        ],
      ),
    );
  }

  Widget _showDialog() {
    return Dialog(
      child: SizedBox(
        width: 300,
        height: 300,
        child: SingleChildScrollView(
          physics: const ClampingScrollPhysics(), // 允许始终滚动
          child: Center(
            child: SizedBox(
              width: 280,
              child: HtmlWidget(
                illustrateHtml,
                textStyle: const TextStyle(color: Colors.black, fontSize: 14),
              ),
            ),
          ),
        ),
      ),
    );
  }

  String _formatExpiryTime(DateTime expiryTime) {
    final duration = expiryTime.difference(DateTime.now());
    final days = duration.inDays;
    final hours = duration.inHours % 24;
    final minutes = duration.inMinutes % 60;
    return '${days}天${hours}小时${minutes}分钟';
  }

  Widget _buildCustomCard(
    ExchangeCard card, {
    bool selectMode = false,
    bool selected = false,
    Function(bool?)? onChanged,
  }) {
    Widget cardContent = Stack(
      children: [
        ClipRRect(
          borderRadius: BorderRadius.circular(12),
          child: Image.network(
            card.imageUrl ?? EcyRandomUtil.randomIconUrl(),
            width: 100,
            height: 80,
            fit: BoxFit.cover,
          ),
        ),
        // 状态角标
        if (card.expiryTime != null)
          Positioned(
            top: 4,
            right: 4,
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
              decoration: BoxDecoration(
                color: Colors.pinkAccent,
                borderRadius: BorderRadius.circular(8),
              ),
              child: Text(
                '剩${_formatExpiryTime(card.expiryTime!)}',
                style: TextStyle(color: Colors.white, fontSize: 10),
              ),
            ),
          ),
        if (selectMode)
          Positioned(
            top: 4,
            left: 4,
            child: Checkbox(
              value: selected,
              onChanged: onChanged,
              shape: CircleBorder(),
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
            ),
          ),
      ],
    );

    // 只在未进入选择模式时可点击弹窗
    if (!selectMode) {
      return GestureDetector(
        onTap: () => _showCardBottomSheet(card),
        child: cardContent,
      );
    } else {
      return cardContent;
    }
  }

  void _showCardBottomSheet(ExchangeCard card) {
    showModalBottomSheet(
      context: context,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
      ),
      isScrollControlled: true,
      builder: (context) {
        return Padding(
          padding: const EdgeInsets.only(top: 24, left: 24, right: 24, bottom: 32),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              // 顶部关闭按钮
              Align(
                alignment: Alignment.topRight,
                child: IconButton(
                  icon: Icon(Icons.close),
                  onPressed: () => Navigator.of(context).pop(),
                ),
              ),
              // 商品图片
              ClipRRect(
                borderRadius: BorderRadius.circular(12),
                child: Image.network(
                  card.imageUrl ?? '',
                  width: 120,
                  height: 120,
                  fit: BoxFit.cover,
                ),
              ),
              SizedBox(height: 16),
              // 商品名
              Text(
                card.name,
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
              ),
              // 你可以根据实际需求补充副标题等
              SizedBox(height: 8),
              Text(
                '【咒术回战】油漆徽章盲袋', // 示例副标题
                style: TextStyle(fontSize: 14, color: Colors.black54),
              ),
              SizedBox(height: 16),
              // 存储时间
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('暂存时间  ', style: TextStyle(fontSize: 14, color: Colors.black54)),
                  Text(
                    '6天23时24分', // 你可以用 _formatExpiryTime(card.expiryTime) 替换
                    style: TextStyle(fontSize: 14, color: Color(0xFFFF7BBE)),
                  ),
                ],
              ),
              SizedBox(height: 32),
              // 按钮区
              Container(
                width: MediaQuery.of(context).size.width * 0.6,
                height: 40,
                decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
                  borderRadius: BorderRadius.circular(20),
                ),
                alignment: Alignment.center,
                child: TextButton(
                  onPressed: () {
                    Navigator.of(context).pop();
                    Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => EcyExchangeSelectTargetPage(),
                    ));
                  },
                  style: TextButton.styleFrom(
                    padding: EdgeInsets.zero,
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                  ),
                  child: Text(
                    '去交换',
                    style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.w700,
                      fontSize: 16,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 16),
              Container(
                width: MediaQuery.of(context).size.width * 0.6,
                height: 40,
                decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
                  borderRadius: BorderRadius.circular(20),
                ),
                child: TextButton(
                  onPressed: () {
                    // 再抽一发逻辑
                  },
                  style: TextButton.styleFrom(
                    padding: EdgeInsets.zero,
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                  ),
                  child: Text(
                    '再抽一发',
                    style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.w700,
                      fontSize: 16,
                    ),
                  ),
                ),
              ),
              // Row(
              //   children: [
              //     Expanded(
              //       child: Container(
              //         height: 40,
              //         decoration: BoxDecoration(
              //           gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
              //           borderRadius: BorderRadius.circular(20),
              //         ),
              //         alignment: Alignment.center,
              //         child: TextButton(
              //           onPressed: () {
              //             // 再抽一发逻辑
              //           },
              //           style: TextButton.styleFrom(
              //             padding: EdgeInsets.zero,
              //             shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
              //           ),
              //           child: Text(
              //             '去交换',
              //             style: TextStyle(
              //               color: Colors.white,
              //               fontWeight: FontWeight.w700,
              //               fontSize: 16,
              //             ),
              //           ),
              //         ),
              //       ),
              //     ),
              //     SizedBox(width: 16),
              //     Expanded(
              //       child: Container(
              //         height: 40,
              //         decoration: BoxDecoration(
              //           gradient: LinearGradient(colors: [Color(0xFFFF7BBE), Color(0xFFFF3E9F)]),
              //           borderRadius: BorderRadius.circular(20),
              //         ),
              //         child: TextButton(
              //           onPressed: () {
              //             // 再抽一发逻辑
              //           },
              //           style: TextButton.styleFrom(
              //             padding: EdgeInsets.zero,
              //             shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
              //           ),
              //           child: Text(
              //             '再抽一发',
              //             style: TextStyle(
              //               color: Colors.white,
              //               fontWeight: FontWeight.w700,
              //               fontSize: 16,
              //             ),
              //           ),
              //         ),
              //       ),
              //     ),
              //   ],
              // ),
            ],
          ),
        );
      },
    );
  }

  Future<bool?> _showConfirmDialog() {
    return showDialog<bool>(
      context: context,
      barrierDismissible: false,
      builder: (context) => Dialog(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
        child: Container(
          width: 280,
          padding: EdgeInsets.only(top: 24, left: 16, right: 16),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Text(
                '当前发货未满足包邮条件',
                style: TextStyle(fontSize: 14, color: Colors.black87),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 8),
              const Text(
                '需支付邮费，是否确定要发货',
                style: TextStyle(fontSize: 14, color: Colors.black87),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 24),
              const Divider(height: 1, thickness: 1),
              SizedBox(
                height: 48,
                child: Row(
                  children: [
                    Expanded(
                      child: TextButton(
                        style: TextButton.styleFrom(
                          padding: EdgeInsets.zero,
                          shape: const RoundedRectangleBorder(borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(16),
                          )),
                        ),
                        onPressed: () => Navigator.of(context).pop(false),
                        child: const Text('取消', style: TextStyle(color: Colors.black, fontSize: 16)),
                      ),
                    ),
                    Container(
                      width: 1,
                      height: double.infinity,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: TextButton(
                        style: TextButton.styleFrom(
                          padding: EdgeInsets.zero,
                          shape: const RoundedRectangleBorder(borderRadius: BorderRadius.only(
                            bottomRight: Radius.circular(16),
                          )),
                        ),
                        onPressed: () => Navigator.of(context).pop(true),
                        child: const Text('确定发货', style: TextStyle(color: Color(0xFFFF7BBE), fontSize: 16, fontWeight: FontWeight.w600)),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}